package com.example.anql.controller;

import com.example.anql.common.ReturnObject;
import com.example.anql.entity.GetShop;
import com.example.anql.service.GetShopService;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.Base64;

/**
 * (GetShop)表控制层
 *
 * @author makejava
 * @since 2022-12-10 12:46:24
 */
@RestController
@RequestMapping("/getShop")
public class GetShopController {
    /**
     * 服务对象
     */
    @Resource
    private GetShopService getShopService;

    /**
     * 上传图片饭base64编码
     */
    @PostMapping("/images")
    public String images(@RequestParam("file") MultipartFile file) throws IOException {

        return   "data:image/png;base64,"+Base64.getEncoder().encodeToString(file.getBytes());
    }




    /**
     * 分页查询
     *
     * @param getShop 筛选条件
     * @return 查询结果
     */
    @PostMapping("/queryByPage")
    public ReturnObject queryByPage(@RequestBody GetShop getShop ) {

        return   getShopService.queryByPage(getShop);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @PostMapping("/queryById")
    public ResponseEntity<GetShop> queryById(@RequestBody GetShop getShop ) {

        return ResponseEntity.ok(this.getShopService.queryById(getShop.getId()));
    }

    /**
     * 新增数据
     *
     * @param getShop 实体
     * @return 新增结果
     */
    @PostMapping("/add")
    public ResponseEntity<GetShop> add(@RequestBody GetShop getShop) {
        return ResponseEntity.ok(this.getShopService.insert(getShop));
    }

    /**
     * 编辑数据
     *
     * @param getShop 实体
     * @return 编辑结果
     */
    @PostMapping("/edit")
    public ResponseEntity<GetShop> edit(@RequestBody GetShop getShop) {
        return ResponseEntity.ok(this.getShopService.update(getShop));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @PostMapping("/deleteById")
    public ResponseEntity<Boolean> deleteById(@RequestBody GetShop getShop) {
        return ResponseEntity.ok(this.getShopService.deleteById(getShop.getId()));
    }

}

